package day9.homeWork;

import java.util.ArrayList;

//b.编写一个程序，启动三个线程，
// 三个线程的名称分别是 A，B，C；
// 每个线程将自己的名称在屏幕上打印5遍，打印顺序是ABCABC…
public class ChooseB {
    public static void main(String[] args) {
        int len = 3;
        int count = 5;
        for (int i = 0; i < len; i++) {
            new PrintChar(i, len, count, (char) (65 + i) + "").start();
        }
    }
}

class PrintChar extends Thread {
    int i;
    int len;
    static int maxCount;

    public PrintChar(int i, int len, int count, String name) {
        super(name);
        this.i = i;
        this.len = len;
        this.maxCount = len * count;
    }

    @Override
    public void run() {
        try {
            String name = Thread.currentThread().getName();
            while (maxCount != 0) {
                synchronized (PrintChar.class) {
                    if ((15 - maxCount) % len == i) {
                        maxCount--;
                        System.out.print(name);
                        PrintChar.class.notifyAll();
                    }
                    PrintChar.class.wait();
                }
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}